<?php
/**
 * +--------------------------------------------------------+
 * @Created by PhpStorm.
 * @Category BaseRequestsPost.php
 * @Depiction:
 * Author: hwy
 * Date: 2020/9/21  15:43
 * +--------------------------------------------------------+
 */

namespace App\Http\Requests;

use Illuminate\Contracts\Validation\Validator;
use Illuminate\Foundation\Http\FormRequest;
use Illuminate\Http\Exceptions\HttpResponseException;

class BaseRequestsPost extends FormRequest
{
    /**
     * Determine if the user is authorized to make this request.
     *
     * @return bool
     */
    public function authorize()
    {
        return true;
    }

    /**
     * 错误信息返回值
     * @param Validator $validator
     * @throws \Illuminate\Validation\ValidationException
     */
    protected function failedValidation(Validator $validator)
    {
        throw new HttpResponseException(response()->json(return_error_msg($validator->errors()->first())));
//        throw new \Illuminate\Validation\ValidationException($validator,['code' => -1, 'message' => $validator->errors()->first()]);
    }

}
